using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Caching;

namespace ThreadManage
{
    public class CacheHelper
    {

        public static void AddItemToCache(string key, string value)
        {
            Cache cache = new Cache();
            //移除时的回调
            CacheItemRemovedCallback onRemove = null;
            if (cache[key] == null)
            {
                //新增
                cache.Add(key, value, null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.High, onRemove);
            }
            else
            {
                //覆盖
                cache.Insert(key, value, null, DateTime.Now.AddSeconds(60), Cache.NoSlidingExpiration, CacheItemPriority.High, onRemove);
            }
        }
        public static object GetCache(string key)
        {
            Cache cache = new Cache();
            return cache.Get(key);
        }
        public static object RemoveCache(string key)
        {
            Cache cache = new Cache();
            return cache.Remove(key);
        }
    }
}
